<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/6/24
 * Time: 14:29
 */

namespace app\controller\admin;
use app\model\admin\Company AS model;

class Company extends Base
{
    public function list(){
        $where = [];
        $post = input('get.');
        !empty($post['company_name']) && $where[] = ['company_name','like','%'.$post['company_name'].'%'];
        !empty($post['address']) && $where[] = ['address','like','%'.$post['address'].'%'];
        !empty($post['nickname']) && $where[] = ['nickname','like','%'.$post['nickname'].'%'];
        !empty($post['mobile']) && $where[] = ['mobile','like','%'.$post['mobile'].'%'];
        $list = model::where($where)
            ->paginate([
                'page' => $this->page,
                'list_rows' => $this->size
            ]);
        return $this->view('/admin/company/list',['list' => $list]);
    }

    public function info(){
        $info = cache('company');
        empty($info) && $info = [['id' => 'company_name','name' => '客户公司'], ['id' => 'address','name' => '公司地址'], ['id' => 'nickname','name' => '询价联系人'], ['id' => 'mobile','name' => '联系方式'],];
        $count = count($info) * 35 + 110;
        return $this->view('/admin/company/info',['info' => $info,'total' => $count]);
    }

    public function save(){
        $id = input('id');
        $news = new model();
        $post = input('post.');
        if (!empty($id)){
            $news->where('id',$id)->save($post);
        }else{
            $news->save($post);
        }
        return $this->msg();
    }

    public function delete($id){
        $ids = input('ids');
        if (!empty($ids)){
            model::where('id','IN',$ids)->delete();
        }else {
            model::find($id)->delete();
        }
        return $this->msg();
    }
}